//
//  CourseNoLoginHeaderView.m
//  ShowYork
//
//  Created by hxh on 2020/8/27.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "LessonHeaderCell.h"

@interface LessonHeaderCell ()
@property (nonatomic,strong)UIView *containView;
@property (nonatomic,strong)UIView *shadowView;
@property (nonatomic,strong)UIImageView *dateImgView;
@property (nonatomic,strong)UIImageView *noDataImgView;
@property (nonatomic,strong)UILabel *noDataLb;
@property (nonatomic,strong)UILabel *dateLb;
@property (nonatomic,strong)UIButton *loginBtn;
@property (nonatomic,strong)UIButton *chineseBtn;
@property (nonatomic,strong)UIButton *mathBtn;
@property (nonatomic,strong)UIButton *englishBtn;
@property (nonatomic,strong)UIView *line;
@end

@implementation LessonHeaderCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    self.shadowView             = [UIView new];
    [self.contentView addSubview:self.shadowView];
    
    self.shadowView.layer.shadowColor   = [UIColor lightGrayColor].CGColor;
    self.shadowView.layer.shadowOffset  = CGSizeMake(0, 0);
    self.shadowView.layer.shadowOpacity = 0.8;
    self.shadowView.layer.shadowRadius  = 8;
    
    
    self.containView = [[UIView alloc]init];
    self.containView.layer.cornerRadius = 14;
    self.containView.layer.masksToBounds = YES;
    self.containView.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
    self.containView.layer.shadowColor = [UIColor colorWithRed:221/255.0 green:221/255.0 blue:221/255.0 alpha:1.0].CGColor;
    self.containView.layer.shadowOffset = CGSizeMake(0,0);
    self.containView.layer.shadowOpacity = 1;
    self.containView.layer.shadowRadius = 5;
    [self.shadowView addSubview:self.containView];
    
    
    
    self.chineseBtn = [[UIButton alloc]init];
    self.chineseBtn.backgroundColor = [UIColor whiteColor];
    [self.chineseBtn setTitle:@"语文" forState:UIControlStateNormal];
    [self.chineseBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.chineseBtn setTitleColor:RGBA(240, 175, 0, 1) forState:UIControlStateSelected];
    self.chineseBtn.selected = YES;
    self.chineseBtn.tag = 0;
    [self.chineseBtn addTarget:self action:@selector(btnMethod:) forControlEvents:UIControlEventTouchUpInside];
    [self.containView addSubview:self.chineseBtn];

    self.mathBtn = [[UIButton alloc]init];
    self.mathBtn.backgroundColor = RGBA(240, 175, 0, 1);
    [self.mathBtn setTitle:@"数学" forState:UIControlStateNormal];
    [self.mathBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.mathBtn setTitleColor:RGBA(240, 175, 0, 1) forState:UIControlStateSelected];
    self.mathBtn.tag = 1;
    [self.mathBtn addTarget:self action:@selector(btnMethod:) forControlEvents:UIControlEventTouchUpInside];
    [self.containView addSubview:self.mathBtn];
    
    self.englishBtn = [[UIButton alloc]init];
    self.englishBtn.backgroundColor = RGBA(240, 175, 0, 1);
    [self.englishBtn setTitle:@"英语" forState:UIControlStateNormal];
    [self.englishBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.englishBtn setTitleColor:RGBA(240, 175, 0, 1) forState:UIControlStateSelected];
    self.englishBtn.tag = 2;
    [self.englishBtn addTarget:self action:@selector(btnMethod:) forControlEvents:UIControlEventTouchUpInside];
    [self.containView addSubview:self.englishBtn];
//    
    self.dateImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"形状"]];
    [self addSubview:self.dateImgView];
    
    self.dateLb = [[UILabel alloc]init];
    self.dateLb.text = @"距离高考还有245天";
    self.dateLb.textColor = RGBA(102, 102, 102, 1);
    self.dateLb.font = font(12);
    [self addSubview:self.dateLb];
//    
    self.loginBtn = [[UIButton alloc]init];
    self.loginBtn.backgroundColor = RGBA(2, 115, 72, 1);
    self.loginBtn.layer.cornerRadius = 22.5;
    self.loginBtn.layer.masksToBounds = YES;
    [self.loginBtn setTitle:@"去登录" forState:UIControlStateNormal];
    [self.loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.loginBtn.titleLabel.font = font(18);
    [self addSubview:self.loginBtn];
    
    self.noDataImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"noData"]];
    [self addSubview:self.noDataImgView];

    self.noDataLb = [[UILabel alloc]init];
    self.noDataLb.text = @"请登录后查看学习情况哦";
    self.noDataLb.textColor = RGBA(153, 153, 153, 1);
    self.noDataLb.font = font(12);
    [self addSubview:self.noDataLb];

    self.line = [[UIView alloc]init];
    self.line.backgroundColor = RGBA(240, 175, 0, 1);
    self.line.layer.cornerRadius = 2;
    self.line.layer.masksToBounds = YES;
    [self addSubview:self.line];

    [self.shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.containView);
    }];
    
    [self.containView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
        make.bottom.equalTo(self.contentView).offset(-15);
        make.height.mas_equalTo(349).priorityHigh();
    }];
    

    [self.chineseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.containView);
        make.height.mas_equalTo(40).priorityHigh();
        make.width.mas_equalTo(self.mathBtn);
        make.right.equalTo(self.mathBtn.mas_left);
    }];
//
    [self.mathBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.mas_equalTo(self.chineseBtn);
        make.width.mas_equalTo(self.englishBtn);
        make.left.equalTo(self.chineseBtn.mas_right);
        make.right.equalTo(self.englishBtn.mas_left);
    }];

    [self.englishBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.mas_equalTo(self.chineseBtn);
        make.width.mas_equalTo(self.chineseBtn);
        make.left.equalTo(self.mathBtn.mas_right);
        make.right.equalTo(self.containView);
    }];
    
    [self.noDataImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.containView);
        make.top.equalTo(self.mathBtn.mas_bottom).offset(70);
    }];

    [self.noDataLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.noDataImgView.mas_bottom).offset(22);
        make.centerX.equalTo(self.noDataImgView);
    }];
//
    [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.containView).offset(15);
        make.right.equalTo(self.containView).offset(-15);
        make.top.equalTo(self.noDataLb.mas_bottom).offset(44);
        make.height.mas_equalTo(44);
    }];

    [self.dateLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.loginBtn);
        make.top.equalTo(self.loginBtn.mas_bottom).offset(15);
    }];

    [self.dateImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.dateLb);
        make.size.mas_equalTo(CGSizeMake(15, 15));
        make.right.equalTo(self.dateLb.mas_left).offset(-10);
        make.bottom.equalTo(self.containView).offset(-15);
    }];

    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.chineseBtn);
        make.bottom.mas_equalTo(self.chineseBtn);
        make.size.mas_equalTo(CGSizeMake(30, 4));
    }];
}

- (void)btnMethod:(UIButton *)btn{
    if (btn.tag == 0) {
        self.chineseBtn.selected = YES;
        self.mathBtn.selected = NO;
        self.englishBtn.selected = NO;
    }
    if (btn.tag == 1) {
        self.chineseBtn.selected = NO;
        self.mathBtn.selected = YES;
        self.englishBtn.selected = NO;
    }
    if (btn.tag == 2) {
        self.chineseBtn.selected = NO;
        self.mathBtn.selected = NO;
        self.englishBtn.selected = YES;
    }
    self.chineseBtn.backgroundColor = self.chineseBtn.selected?[UIColor whiteColor]:RGBA(240, 175, 0, 1);
    self.mathBtn.backgroundColor = self.mathBtn.selected?[UIColor whiteColor]:RGBA(240, 175, 0, 1);
    self.englishBtn.backgroundColor = self.englishBtn.selected?[UIColor whiteColor]:RGBA(240, 175, 0, 1);
    [self.line mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.chineseBtn).offset(btn.tag * (kScreenW - 30)/3);
    }];
}
+(instancetype)cellWithTableView:(UITableView *)tableView{
    NSString *ID = @"LessonHeaderCell";
    LessonHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[LessonHeaderCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}


@end
